#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: a_template.py 
@version:
@time: 2022/03/05 
"""
from TapClientConnector.connector.tap_connector00_base import *


class ATemplate:
    def __init__(self):
        ...

    @connector_exec_logger
    def _exec(self, data):
        ...

    @connector_query_logger
    def _query(self, index):
        """
        es 作为目标，同步的表都会变成小写
        :param index:
        :return:
        """
        es_raw_data = self.connector.search(index=index.lower())
        return [data.get('_source') for data in es_raw_data.get('hits').get('hits')]

    # COMMON FUNC
    def exec(self, _exec_):
        return self._exec(_exec_)

    def query(self, index):
        return self._query(index)

    def show_dbs(self):
        ...

    @not_support
    @connector_query_logger
    def show_tables(self):
        result = [(name,) for name, _ in self.connector.indices.get_alias().items()]
        return result

    @not_support
    @connector_query_logger
    def count(self):
        ...

    # GENERAGE

    @not_support
    def generate_create(self):
        ...

    @not_support
    def generate_drop(self, index):
        """
        :param index:
        :return:
        """
        return index.lower()

    @not_support
    def generate_insert(self):
        ...

    @not_support
    def generate_delete(self, table, where):
        ...

    @not_support
    def generate_select(self, index):
        """
        :param index:
        :return:
        """
        return index.lower()

    @not_support
    def generate_update(self, table, update, where):
        ...

    def close(self):
        ...

    def __del__(self):
        ...
